﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Text;
using VCC.Model;
using VCC.Site.Properties;
using VCC.Lib.Common;
using VCC.Site.ViewModels;
using VCC.Lib;
using VCC.Lib.Mail;
using VCC.Site.Properties;

namespace VCC.Site.Controllers
{
    public class ContactController : Controller
    {
        //
        // GET: /Contact/

        public ActionResult Index()
        {
            ContactModel model = new ContactModel();
            //model.LanguageID = Utils.ParseInt(Session["LanguageID"].ToString(), 1);
            return View(model);
        }
       
        //
        // POST: /Contact/Send/
        [HttpPost]
        public ActionResult Send(ContactModel contact)
        {
            try
            {
                UpdateModel(contact);
                ChoVietDataContext eDataContact = new ChoVietDataContext();
                contact.ContactUs.CreatedDate = DateTime.Now;
                contact.ContactUs.IsView = false;
                eDataContact.ContactUs.InsertOnSubmit(contact.ContactUs);
                eDataContact.SubmitChanges();
                var mailBody = new StringBuilder();
                //mailBody.Append("From:");
                //mailBody.Append("<br />");
                mailBody.Append("<strong>Full Name: </strong>");
                mailBody.Append(contact.ContactUs.Name);
                mailBody.Append("<br />");
                mailBody.Append("<strong>Email: </strong>");
                mailBody.Append(contact.ContactUs.Email);
                mailBody.Append("<br />");
                mailBody.Append("<strong>Mobile: </strong>");
                mailBody.Append(contact.ContactUs.PhoneNumber);
                mailBody.Append("<br />");
                mailBody.Append("<br />");
                mailBody.Append("<strong>Subject: </strong>");
                mailBody.Append(contact.ContactUs.Title);
                mailBody.Append("<br />");
                mailBody.Append("<strong>Content: </strong>");
                mailBody.Append("<br />");
                mailBody.Append(contact.ContactUs.Content);
                mailBody.Append("<br />");
                SmtpMailer.sendMail(Settings.Default.DefaultRecieverEmailContact,Settings.Default.DefaultSenderMail, "Customer contact - " + contact.ContactUs.Name + ": " + contact.ContactUs.Title, mailBody.ToString(), "Berrykitchen.com.au");
                return View("Success");
            }
            catch (Exception exp)
            {
                ErrorLog.WriteLog(exp);
                return View("Fail");
            }
        }

    }
}
